/**
* Choose a name for subclassed Array
*/
Stack = (function(){ /* (C) Andrea Giammarchi - Mit Style License */
 
    /**
     * Your personal Array constructor
     */
    function Stack(length){
        if(arguments.length === 1 && typeof length === "number")
            this.length = -1 <length && length === length <<1>> 1 ? length : this.push(length);
        else if(arguments.length)
            this.push.apply(this, arguments);
    };
 
    /* Solution 1:
          Declaration of generic function
          with an array as prototype */
    function Array(){};
    Array.prototype = [];
 
    /* Solution 2:
          use the prototype chain to inherit
          Array constructor and its native prototype */
    Stack.prototype = new Array;
 
    /* Solution 3:
          overwrite inherited length with zero value */
    Stack.prototype.length = 0;
 
    /* Solution 4:
          redeclare toString method in this way
          to let JScript core feel better */
    Stack.prototype.toString = function(){
        return  this.slice(0).toString();
    };
 
    /**
     * Return and assign subclassed Array
     */
    Stack.prototype.constructor = Stack;
    return  Stack;
 
})();

ArrayObject = function(){
    /**
     * Advanced Subclassed Array for every browser.
     * @author      Andrea Giammarchi
     * @site        devpro.it
     * @blog        webreflection.blogspot.com
     * @date        2008/05/24
     * @dependencies    Stack OR Stack Lite + Stack Extended
     * @requires    IE 5.5+ , FF 1+ , Opera 8+ , Safari 2+
     * @license     Mit Style
     */
    function push(self, arguments){
        self.push.apply(self, arguments);
        return  self;
    };
    function ArrayObject(){
        if(arguments.length)
            Stack.apply(this, arguments);
    };
    var filter  = Stack.prototype.filter,
        map     = Stack.prototype.map,
        slice   = Stack.prototype.slice,
        splice  = Stack.prototype.splice;
    ArrayObject.create = function(Array){
        return  Array ? push(new ArrayObject, Array instanceof Stack ? slice.call(Array, 0) : Array) : new ArrayObject;
    };
    ArrayObject.prototype = new Stack;
    ArrayObject.prototype.constructor = ArrayObject;
    ArrayObject.prototype.filter = function(){
        return  push(new ArrayObject, filter.apply(this, arguments));
    };
    ArrayObject.prototype.map = function(){
        return  push(new ArrayObject, map.apply(this, arguments));
    };
    ArrayObject.prototype.slice = function(){
        return  push(new ArrayObject, slice.apply(this, arguments));
    };
    ArrayObject.prototype.splice = function(){
        return  push(new ArrayObject, splice.apply(this, arguments));
    };
    ArrayObject.prototype.to = function(constructor){
        return  this.constructor === constructor ? this : push(new constructor, slice.call(this, 0));
    };
    ArrayObject.prototype.valueOf = function(){
        return  this.length;
    };
    return  ArrayObject;
}();

Array.prototype.to = ArrayObject.to;
